<template>
	<view>
		<image src="../../static/logo-1.png" class="logo" mode="widthFix"></image>
		<view class="logo-title">Teams在线办公协同系统</view>
		<view class="logo-subtitle">v1.0</view>
		<view>
			<button class="login-btn" open-type="getUserInfo" @click="login()">登陆系统</button>
		</view>
		<view class="register-container">
					没有账号？
					<text class="register" @tap="toRegister()">立即注册</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data:{
					code:''
				}
				
			}
		},

		methods: {
			toRegister:function(){
								uni.navigateTo({
									url:"../register/register"
								})
							},
			login(){
				var that=this
				uni.login({
					provider:'weixin',
					success:function (resp){
						that.data.code=resp.code
						that.ajax(that.url.login,'POST',that.data,function(res){
							console.log("res:"+res)
							if(res.data.code==200){
								console.log(res)
								uni.showToast({
									icon: 'none',
									title: '登录成功'
								})
								uni.setStorageSync("permissions",res.data.permissions)
								uni.setStorageSync("token",res.data.token)
								uni.setStorageSync("userName",res.data.userName)
								uni.setStorageSync("photo",res.data.photo)
								uni.setStorageSync("deptName",res.data.deptName)
								uni.setStorageSync("date",res.data.date)
								//todo 把用户的头像也存进去算了，还有姓名和部门不然每次都去请求不是麻烦死了，id别存就行
								uni.switchTab({
									url: "/pages/index/index"
								})
							}
						})
					}
				})
			}
					
		}
	}
</script>

<style lang="less">
	@import url('login.less'); 
</style>
